﻿using System;
using DevExpress.Xpo.DB;
using SecuritySpace.WPF.Demo;
using SmartPeople.Framework.Security.Providers.XPO;
using SmartPeople.Framework.SecuritySpace;

namespace SecuritySpace.WPF.Demo
{
    public class XPOProviderFactory : ISecuritySpaceProviderFactory
    {
        private static ISecuritySpace securitySpaceProvider;

        public ISecuritySpace GetSecuritySpace()
        {
            if (securitySpaceProvider == null)
            {
                securitySpaceProvider = GetSecuritySpace("/");
            }
            return securitySpaceProvider;
        }

        public ISecuritySpace GetSecuritySpace(string applicationName)
        {
            //string xConnectionString = @"data source=D:\SecuritySpaceTests.mdb;provider=Microsoft.Jet.OLEDB.4.0;";
            //string xConnectionString = @"data source=D:\SecuritySpaceTests.mdb;provider=Microsoft.ACE.OLEDB.12.0;";
            //ISecuritySpace securitySpace = new XPSecuritySpace(applicationName, xConnectionString);
            ISecuritySpace securitySpace = new XPSecuritySpace(applicationName, ConnectionString);
            return securitySpace;
        }

        private static string ConnectionString
        {
            get
            {
                //INFO: Please inform each other when changing this
                String server = "ABRAHAM1\\SQL2005";
                String userid = "sa";
                String password = "dpsa";
                String database = "SecuritySpaceTests";
                string connectionString =
                    MSSqlConnectionProvider.GetConnectionString(server, userid, password, database);
                //				string connectionString =ConfigurationSettings.AppSettings["ConnectionString"];
                return connectionString;
            }
        }

        public ISecurityUsersProvider SecurityUserProvider
        {
            get { return new XPSecurityUserProvider(); }
        }
    }
}